//
//  LPTIncomeDetailTableViewController.m
//  LPTClient
//
//  Created by mac on 2018/12/12.
//  Copyright © 2018年 zhaodd. All rights reserved.
//

#import "LPTIncomeDetailTableViewController.h"
#import "LPTIncomeDetailBalanceTableViewCell.h"
#import "LPTIncomeDtailTableViewCell.h"

@interface LPTIncomeDetailTableViewController ()

@end

@implementation LPTIncomeDetailTableViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self initDataSource];
    
    [self initSubViews];
}

-(void)initSubViews
{
    self.tableView.tableFooterView = [UIView new];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

-(void)initDataSource
{
    if (self.type == kZhanghuliushuiType) {
        
    if ([[self.dic valueForKey:@"flow_type"] isEqualToString:@"cash"]) {
        
        //提现
        NSDictionary *dic1 = @{@"类型":@"提现"};
        NSDictionary *dic2 = @{@"详情":@"账号15347389242784324"};
        NSDictionary *dic3 = @{@"余额":self.dic[@"balance"]};
        NSDictionary *dic4 = @{@"时间":self.dic[@"created_at"]};
        
        NSString *amountStr;
        if ([self.dic[@"change"] floatValue] > 0) {
            amountStr = [NSString stringWithFormat:@"+%@",self.dic[@"change"]];
        }else{
            amountStr = self.dic[@"change"];
        }
        
        NSMutableArray *array = [NSMutableArray arrayWithObjects:amountStr,dic1,dic2,dic3,dic4, nil];
        [self.dataSource addObject:array];
        [self.tableView reloadData];
        
    }else if([[self.dic valueForKey:@"flow_type"] isEqualToString:@"invite"]){
        
        NSDictionary *dic1 = @{@"类型":@"邀请奖金"};
        NSDictionary *dic2 = @{@"详情":@"账号15347389242784324"};
        NSDictionary *dic3 = @{@"余额":self.dic[@"balance"]};
        NSDictionary *dic4 = @{@"时间":self.dic[@"created_at"]};
        
        NSString *amountStr;
        if ([self.dic[@"change"] floatValue] > 0) {
            amountStr = [NSString stringWithFormat:@"+%@",self.dic[@"change"]];
        }else{
            amountStr = self.dic[@"change"];
        }
        
        NSMutableArray *array = [NSMutableArray arrayWithObjects:amountStr,dic1,dic2,dic3,dic4, nil];
        [self.dataSource addObject:array];
        [self.tableView reloadData];
        
    }else if ([[self.dic valueForKey:@"flow_type"] isEqualToString:@"income"]){
        
        NSDictionary *dic1 = @{@"类型":@"收益"};
        NSDictionary *dic2 = @{@"详情":@"账号15347389242784324"};
        NSDictionary *dic3 = @{@"余额":self.dic[@"balance"]};
        NSDictionary *dic4 = @{@"时间":self.dic[@"created_at"]};
        
        NSString *amountStr;
        if ([self.dic[@"change"] floatValue] > 0) {
            amountStr = [NSString stringWithFormat:@"+%@",self.dic[@"change"]];
        }else{
            amountStr = self.dic[@"change"];
        }
        
        NSMutableArray *array = [NSMutableArray arrayWithObjects:amountStr,dic1,dic2,dic3,dic4, nil];
        [self.dataSource addObject:array];
        [self.tableView reloadData];
        
        }
        
    }else if(self.type == kTixianjiluType){
        
        //提现
        NSDictionary *dic1 = @{@"时间":self.dic[@"created_at"]};
        NSDictionary *dic2 = @{@"银行":self.dic[@"bank_card"][@"bank"]};
        NSDictionary *dic3 = @{@"卡号":self.dic[@"bank_card"][@"account_number"]};
        NSDictionary *dic4 = @{@"开户人":self.dic[@"bank_card"][@"account_holder"]};
        
        NSDictionary *dic5 = @{@"提现金额":self.dic[@"amount"]};
        
        NSString *feilvString = [[NSString stringWithFormat:@"%@",self.dic[@"rate"]] stringByAppendingString:@"%"];
        NSDictionary *dic6 = @{@"费率":feilvString};
        NSDictionary *dic7 = @{@"实际到账":self.dic[@"actual_amount"]};
        
        NSString *statusString = [self.dic[@"status"] integerValue] == 0?@"待审核":@"已通过审核";
        NSDictionary *dic8 = @{@"状态":statusString};
        
        NSString *amountStr;
        if ([self.dic[@"amount"] floatValue] > 0) {
            amountStr = [NSString stringWithFormat:@"+%@",self.dic[@"amount"]];
        }else{
            amountStr = self.dic[@"amount"];
        }
        
        NSArray *array = @[@[amountStr,dic1,dic2,dic3,dic4],@[dic5,dic6,dic7,dic8]];
        [self.dataSource addObjectsFromArray:array];
        [self.tableView reloadData];
        
    }else{
        
        //收益明细
        NSDictionary *dic1 = @{@"时间":self.dic[@"created_at"]};
        NSDictionary *dic2 = @{@"订单号":self.dic[@"commodity"][@"no"]};
        
        NSString *typeString;
        if ([self.dic[@"commodity_type"] isEqualToString:@"order"]) {
            typeString = @"药品订单";
        }else if ([self.dic[@"commodity_type"] isEqualToString:@"text_visit"]){
            
            typeString = @"诊金";
        }
        
        NSDictionary *dic3 = @{@"类型":typeString};
        NSDictionary *dic4 = @{@"总金额":self.dic[@"amount"]};
        
        NSString *biliString = [[NSString stringWithFormat:@"%@",self.dic[@"proportion"]] stringByAppendingString:@"%"];
        NSDictionary *dic5 = @{@"比例":biliString};
        
        NSDictionary *dic6 = @{@"收入金额":self.dic[@"account_log"][@"change"]};
        
        NSDictionary *dic7 = @{@"状态":[self.dic[@"status"] integerValue] == 1?@"已到账":@"未到账"};
        NSDictionary *dic8 = @{@"账户余额":self.dic[@"account_log"][@"balance"]};
        
        NSString *amountStr;
        if ([self.dic[@"amount"] floatValue] > 0) {
            amountStr = [NSString stringWithFormat:@"+%@",self.dic[@"amount"]];
        }else{
            amountStr = self.dic[@"amount"];
        }
        
        NSArray *array = @[@[amountStr,dic1,dic2,dic3],@[dic4, dic5,dic6,dic7,dic8]];
        [self.dataSource addObjectsFromArray:array];
        [self.tableView reloadData];
        
    }
    
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return self.dataSource.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [self.dataSource[section] count];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0 && indexPath.section == 0) {
        
        return 116;
        
    }else{
        
        return 44;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 1) {
        return 8;
    }else{
        return 0.1f;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = self.dataSource[indexPath.section][indexPath.row];
    
    if ([dic isKindOfClass:[NSDictionary class]]) {
        
        LPTIncomeDtailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LPTIncomeDtailTableViewCell" forIndexPath:indexPath];
        cell.titleLab.text = [[dic allKeys] firstObject];
        cell.detailLab.text = [dic objectForKey:[[dic allKeys] firstObject]];
        return cell;
        
    }else{
        
        LPTIncomeDetailBalanceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LPTIncomeDetailBalanceTableViewCell" forIndexPath:indexPath];
        cell.balanceLabel.text = (NSString *)dic;
        
        return cell;
    }
    
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
